/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/8/25
 * Time: 18:11
 */
public class Solution {
    public int pivotIndex(int[] nums) {
        int[] f = new int[nums.length];
        int[] g = new int[nums.length];
        //前缀和
        for (int i = 1; i < nums.length; i++) {
            f[i] = f[i - 1] + nums[i - 1];
        }
        //后缀和
        for (int i = nums.length - 2; i >= 0; i--) {
            g[i] = g[i + 1] + nums[i + 1];
        }
        for (int i = 0;i < nums.length;i++) {
            if (g[i] == f[i]) {
                return i;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        Solution solution = new Solution();
        int ret = solution.pivotIndex(new int[]{1, 7, 3, 6, 5, 6});
        System.out.println(ret);
    }
}